package com.hc.listener;


import java.awt.Container;
import java.awt.Point;
import java.awt.event.AdjustmentEvent;
import java.awt.event.AdjustmentListener;

import javax.swing.JScrollPane;

import com.hc.commView.TopoToolBar;
import com.hc.window.MainPanel;

public class MyAdjustmentListener {
	Point location;
    int x, y;
	
	public MyAdjustmentListener(JScrollPane scrollPane, final Container toolbar){
		location = toolbar.getLocation();
		scrollPane.getVerticalScrollBar().addAdjustmentListener(new AdjustmentListener(){
			@Override
			public void adjustmentValueChanged(AdjustmentEvent e) {
				y = e.getValue();
				toolbar.setLocation(location.x+x-(MainPanel.splitPane.getDividerLocation()-TopoToolBar.split), location.y+y);
			}
			
		});
		scrollPane.getHorizontalScrollBar().addAdjustmentListener(new AdjustmentListener(){
			@Override
			public void adjustmentValueChanged(AdjustmentEvent e) {
				x = e.getValue();
				toolbar.setLocation(location.x+x-(MainPanel.splitPane.getDividerLocation()-TopoToolBar.split), location.y+y);
			}
			
		});
	}


}
